package com.ruoyi.ipms_crm.service.impl;/*
 *@Date:2022/4/21 - 04 - 21 - 11:18
 */

import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.ipms_crm.entity.IpmsTracking;
import com.ruoyi.ipms_crm.mapper.IpmsTrackingMapper;
import com.ruoyi.ipms_crm.service.IIpmsTrackingService;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * Service业务层处理
 *
 * @author qs
 * @date 2022-04-21
 */

@Service
public class IpmsTrackingServiceImpl implements IIpmsTrackingService {

    @Autowired(required = false)
    private IpmsTrackingMapper ipmsTrackingMapper;

    /**
     * 查询
     */
    @Override
    public IpmsTracking selectIpmsTrackingByTrackingId(Integer trackingId) {
        return ipmsTrackingMapper.selectIpmsTrackingByTrackingId(trackingId);
    }

    /**
     * 查询列表
     */
    @Override
    public List<IpmsTracking> selectIpmsTrackingList(IpmsTracking ipmsTracking) {
        return ipmsTrackingMapper.selectIpmsTrackingList(ipmsTracking);
    }

    /**
     * 新增
     */
    @Override
    public int insertIpmsTracking(IpmsTracking ipmsTracking) {
        LoginUser loginUser= SecurityUtils.getLoginUser();
        //员工id
        int userid = Integer.parseInt(loginUser.getUserid()+"");
        ipmsTracking.setUserId(userid);
        //创建时间
        ipmsTracking.setCreateTime(DateUtils.getNowDate());
        //乐观锁
        ipmsTracking.setVersion(Constants.VERSION_LOCK);
        //逻辑删除
        ipmsTracking.setIsDelete(Constants.IS_DELETED);
        //创建人
        ipmsTracking.setCreateBy(loginUser.getSysUser().getNickName());
        //更新人
        ipmsTracking.setUpdateBy(loginUser.getSysUser().getNickName());
        //更新时间
        ipmsTracking.setUpdateTime(DateUtils.getNowDate());
        return ipmsTrackingMapper.insertIpmsTracking(ipmsTracking);
    }

    /**
     * 修改
     */
    @Override
    public int updateIpmsTracking(IpmsTracking ipmsTracking) {
        ipmsTracking.setUpdateTime(DateUtils.getNowDate());
        return ipmsTrackingMapper.updateIpmsTracking(ipmsTracking);
    }

    /**
     * 批量删除
     */
    @Override
    public int deleteIpmsTrackingByTrackingIds(Integer[] trackingIds) {
        return ipmsTrackingMapper.deleteIpmsTrackingByTrackingIds(trackingIds);
    }

    /**
     * 删除信息
     */
    @Override
    public int deleteIpmsTrackingByTrackingId(Integer trackingId) {
        return ipmsTrackingMapper.deleteIpmsTrackingByTrackingId(trackingId);
    }

    @Override
    public List<IpmsTracking> selectCustomerTracking(Integer customerId) {
        return ipmsTrackingMapper.selectCustomerTracking(customerId);
    }
}
